package com.wyb.service.impl;

import com.wyb.mapper.UserMapper;
import com.wyb.constant.Result;
import com.wyb.pojo.User;
import com.wyb.service.GetAuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Service
public class GetAuthorServiceImpl implements GetAuthorService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public Result getAuthor(int userId) {

        User user = userMapper.selectById(userId);

        if(!Objects.isNull(user)){
            Map<String,String> map = new HashMap<String ,String >();
            map.put("nickName",user.getNickName());
            map.put("avatar", user.getAvatar());
            return new Result(200, "成功获取作者昵称",map);
        }else{
            return new Result(201, "获取作者昵称失败，可能是无效的userId");
        }

    }
}
